package com.jianying.day04;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * ClassName: Flink05_Union
 * Package: com.atguigu.day04
 * Description:
 *
 * @Author: tubage
 * @Create: 2024/4/2 13:59
 * @Version: 1.0
 */
public class Flink05_Union {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        env.setParallelism(1);
        DataStreamSource<String> socketDS1 = env.socketTextStream("localhost", 8888);
        DataStreamSource<String> socketDS2 = env.socketTextStream("localhost", 8889);

        DataStreamSource<Integer> ds3 = env.fromElements(1, 2, 3);
        SingleOutputStreamOperator<String> ds4 = ds3.map(i -> i + "");

        // TODO union 合流  流中类型要相同
        DataStream<String> unionDS = socketDS1.union(socketDS2, ds4);
        unionDS.print();
        env.execute();
    }
}
